package main

import (
	"fmt"
	"io"
	"os"
)

func main0501() {
	fp, err := os.Create("./a.txt")
	if err != nil {
		fmt.Println("文件创建失败")
		return
	}
	defer fp.Close()
	fp.WriteString("hellow world")
}

func main0502() {
	fp, err := os.Create("./b.txt")
	if err != nil {
		fmt.Println("文件创建失败")
		return
	}
	defer fp.Close()
	slice := []byte{'h', 'e', 'l', 'l', 'o'}
	count, _ := fp.Write(slice)
	fmt.Println(count)

}

func main() {
	//fp, err := os.Create("./a.txt")
	fp, err := os.OpenFile("./a.txt", os.O_RDWR, 6)
	if err != nil {
		fmt.Println("文件创建失败")
		return
	}
	defer fp.Close()
	// 获取光标流的位置
	//count, _ := fp.Seek(0, os.SEEK_END)
	count, _ := fp.Seek(0, io.SeekEnd)
	fp.WriteAt([]byte("hello world"), count)
}
